﻿
$(".cancel-btn").click(

    function () {

        $("#lastname").val("");
        $("#firstname").val("");
        $("#email").val("");

        $("#userphone").val("");

        $("#zone").val("");
        $("#agencylastname").val("");
        $("#agencyfirstname").val("");

        $("#agencyemail").val("");

        $("#agencyphone").val("");

        $("#agencyzone").val("");

        $("#agencyname").val("");

    }
    )
//获取url中的参数
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}
function List() {

    var tid = getQueryString("id");
    if (tid > 0) {
        $.ajax({
            url: '/collection/ListP',
            type: 'GET', //GET
            async: true,    //或false,是否异步
            data: { typeId: tid },
            dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            beforeSend: function (xhr) {
                console.log(xhr)
                console.log('发送前')
            },
            success: function (res, textStatus, jqXHR) {
                var html = '';
                //第二次方式  
                for (var i = 0; i < res.length; i++) {
                    html += " <li> <a href='pd.shtml?pid=" + res[i].id + "'><img src=" + res[i].pcimgtitile + " alt=" + res[i].name + " /><p>" + res[i].name + "</p></a> </li>"
                }
                $(".pro-ul").html(html)
                console.log(res)
                console.log(textStatus)
                console.log(jqXHR)
            },
            error: function (xhr, textStatus) {
                console.log('错误')
                console.log(xhr)
                console.log(textStatus)
            },
            complete: function () {
                console.log('结束')
            }
        })
    }
}
List();
function ListP() {

    var tid = getQueryString("pid");
    if (tid > 0) {
        $.ajax({
            url: '/collection/Dp',
            type: 'GET', //GET
            async: true,    //或false,是否异步
            data: { id: tid },
            dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            beforeSend: function (xhr) {
                console.log(xhr)
                console.log('发送前')
            },
            success: function (res, textStatus, jqXHR) {
                var html = '';
                $('.pro-info h3').html(res.name);
                //第二次方式  
                $('.pro-info p:first').html(res.des.replace(/\n/g, "<br />"));
                for (var i = 0; i < res.imgList.length; i++) {
                    html += " <p> <a ><img src=" + res.imgList[i] + " ></a> </p>"
                }
                $('.pro-pic').html(html);


                console.log(res)
                console.log(textStatus)
                console.log(jqXHR)
            },
            error: function (xhr, textStatus) {
                console.log('错误')
                console.log(xhr)
                console.log(textStatus)
            },
            complete: function () {
                console.log('结束')
            }
        })
    }
}
ListP();
function ListMP() {

    var tid = getQueryString("mpid");
    if (tid > 0) {
        $.ajax({
            url: '/collection/Dp',
            type: 'GET', //GET
            async: true,    //或false,是否异步
            data: { id: tid },
            dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            beforeSend: function (xhr) {
                console.log(xhr)
                console.log('发送前')
            },
            success: function (res, textStatus, jqXHR) {
                var html = '';
                $('.pro-txt h3').html(res.name);
                //第二次方式  
                $('.pro-txt p:first').html(res.des.replace(/\n/g, "<br />"));
                for (var i = 0; i < res.imgList.length; i++) {
                    html += "<div class='swiper-slide'><img src=" + res.imgList[i] + " ></div>"
                }
                $('.swiper-wrapper').html(html);


                console.log(res)
                console.log(textStatus)
                console.log(jqXHR)
            },
            error: function (xhr, textStatus) {
                console.log('错误')
                console.log(xhr)
                console.log(textStatus)
            },
            complete: function () {
                console.log('结束')
            }
        })
    }
}
ListMP();
function ListM() {

    var tid = getQueryString("mid");
    if (tid > 0) {
        $.ajax({
            url: '/collection/ListP',
            type: 'GET', //GET
            async: true,    //或false,是否异步
            data: { typeId: tid },
            dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            beforeSend: function (xhr) {
                console.log(xhr)
                console.log('发送前')
            },
            success: function (res, textStatus, jqXHR) {
                var html = '';
                //第二次方式  
                for (var i = 0; i < res.length; i++) {
                    html += " <li> <a href='pd.shtml?mpid=" + res[i].id + "'><div><img src=" + res[i].pcimgtitile + " alt=" + res[i].name + " /></div><p>" + res[i].name + "</p></a> </li>"
                }
                $(".pro-ul").html(html)
                console.log(res)
                console.log(textStatus)
                console.log(jqXHR)
            },
            error: function (xhr, textStatus) {
                console.log('错误')
                console.log(xhr)
                console.log(textStatus)
            },
            complete: function () {
                console.log('结束')
            }
        })
    }
}
ListM();
function checkMobile(sMobile) {
    if (!(/^1[3|2|4|6|7|9|5|8][0-9]\d{4,8}$/.test(sMobile))) {

        return false;
    }
    return true
}
function yuye() {

    var yuyueModel = new Object;
    yuyueModel.name = $("#name").val();
    if ($("#name").val().length < 1) {
        alert("请输入姓名")
        return false
    }
    yuyueModel.sex = $("#sex").val();

    if ($("#sex").val() == "0") {
        alert("请选择性别")
        return false
    }
    yuyueModel.phone = $("#memberPhone").val();
    if ($("#memberPhone").val().length < 1) {
        alert("请输入手机号")
        return false
    } if (!checkMobile($("#memberPhone").val())) {
        alert("请输入正确手机号")
        return false
    }
    yuyueModel.yuyuetime = $("#usertime").val();
    if ($("#usertime").val().length < 1) {
        alert("请选择时间")
        return false
    }
    yuyueModel.dizhi = $("#address").val();
    if ($("#address").val().length < 1) {
        alert("请输入地址")
        return false
    }
    $.ajax({
        url: '/collection/YuYue',
        type: 'POST', //GET
        async: true,    //或false,是否异步
        data: yuyueModel,
        dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
        beforeSend: function (xhr) {
            console.log(xhr)
            console.log('发送前')
        },
        success: function (data, textStatus, jqXHR) {
            if (data == 1) {
                alert("提交成功")
            } else {
                alert("失败")


            }
            console.log(data)
            console.log(textStatus)
            console.log(jqXHR)
        },
        error: function (xhr, textStatus) {
            console.log('错误')
            console.log(xhr)
            console.log(textStatus)
        },
        complete: function () {
            console.log('结束')
        }
    })
}
$(".submit-btn").click(
        function () {
            yuye();
        }

    );
function fChkMail(szMail) {
    var szReg = /^[A-Za-zd]+([-_.][A-Za-zd]+)*@([A-Za-zd]+[-.])+[A-Za-zd]{2,5}$/;
    var bChk = szReg.test(szMail);
    return bChk;
}
function liuyan(type) {
    var liuyanModel = new Object;
    if (type == 2) {
        liuyanModel.name = $("#agencylastname").val();
        if ($("#agencylastname").val().length < 1) {
            alert("请输入姓名")
            return false
        }
        liuyanModel.sur = $("#agencyfirstname").val();

        if ($("#agencyfirstname").val() == "0") {
            alert("请选择性别")
            return false
        }
        liuyanModel.email = $("#agencyemail").val();
        if ($("#agencyemail").val().length < 1) {
            alert("请输入邮箱")
            return false
        }
        liuyanModel.phone = $("#agencyphone").val();
        if ($("#agencyphone").val().length < 1) {
            alert("请输入手机号")
            return false
        }
        liuyanModel.jigou = $("#agencyname").val();
        if ($("#agencyname").val().length < 1) {
            alert("请输入机构")
            return false
        }
        liuyanModel.guojia = $("#agencyzone").val();
        if ($("#agencyzone").val().length < 1) {
            alert("请输入国家地区")
            return false
        }
      
    } else {
        liuyanModel.name = $("#lastname").val();
        if ($("#lastname").val().length < 1) {
            alert("请输入姓名")
            return false
        }
        liuyanModel.sur = $("#firstname").val();
        if ($("#firstname").val() == "0") {
            alert("请选择性别")
            return false
        }
        liuyanModel.email = $("#email").val();

        if ($("#email").val().length < 1) {
            alert("请输入邮箱")
            return false
        }

        liuyanModel.phone = $("#userphone").val();
        if ($("#userphone").val().length < 1) {
            alert("请输入手机号")
            return false
        }
        liuyanModel.type = type;
        liuyanModel.guojia = $("#zone").val();
        if ($("#zone").val().length < 1) {
            alert("请输入国家地区")
            return false
        }


    }
    $.ajax({
        url: '/collection/LianXi',
        type: 'POST', //GET
        async: true,    //或false,是否异步
        data: liuyanModel,
        dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
        beforeSend: function (xhr) {
            console.log(xhr)
            console.log('发送前')
        },
        success: function (data, textStatus, jqXHR) {
            if (data == 1) {
                alert("提交成功")
            } else {
                alert("失败")


            }
            console.log(data)
            console.log(textStatus)
            console.log(jqXHR)
        },
        error: function (xhr, textStatus) {
            console.log('错误')
            console.log(xhr)
            console.log(textStatus)
        },
        complete: function () {
            console.log('结束')
        }
    })
}